/* eslint-disable import/no-anonymous-default-export */
import * as types from "./../actions-type";

const delay = (ms) => {
  return new Promise((res) => {
    setTimeout(() => {
      res("阿德托昆博");
    }, ms);
  });
};

export default {
  setName(data) {
    return { type: types.SET_NAME, payload: data };
  },
  setAge(data) {
    return { type: types.SET_AGE, payload: data };
  },
  setNumber(data) {
    return { type: types.SET_NUMBER, payload: data };
  },
  asyncSetName(name) {
    //派发一个函数
    return (dispatch) => {
      //延迟两秒派发动作
      delay(2000).then(() => {
        dispatch({ type: types.ASYNC_SET_NAME, payload: name });
      });
    };
  },
  promiseSetName(dispatch, name) {
    return new Promise((resolve, reject) => {
      resolve({ type: types.PROMISE_SET_NAME, payload: name });
    });
  },
  // promiseSetName(dispatch, name) {
  //   return new Promise((resolve, reject) => {
  //     console.log(1235555);
  //     delay(1000).then(() => {
  //       dispatch({ type: types.PROMISE_SET_NAME, payload: name });
  //     });
  //   });
  // },
};
